<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>分类管理</title>
<link rel="stylesheet" type="text/css"	href="../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/icon.css">
<script type="text/javascript" src="../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript"	src="../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../static/js/jquery.validate.js"></script>
<script type="text/javascript" src="../static/js/index.js"></script>
<link rel="stylesheet" type="text/css"	href="../static/zTree/css/zTree.css">
<link rel="stylesheet" type="text/css"	href="../static/zTree/css/zTreeStyle/zTreeStyle.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/default/easyui.css">
<script type="text/javascript"	src="../static/zTree/js/jquery.ztree.core.js"></script>
<script type="text/javascript"	src="../static/zTree/js/jquery.ztree.excheck.js"></script>
<script type="text/javascript"	src="../static/zTree/js/jquery.ztree.exedit.js"></script>
<%
String para =request.getParameter("f_catalog_programatype");
int f_catalog_programatype = 1;
if(para != null)
	f_catalog_programatype = Integer.valueOf(para);
String thisid =String.valueOf( request.getParameter("catalogId"));//当前需要定位的id
if("null".equals(thisid)){
	thisid ="0";
}
%>
<script type="text/javascript">
var thisid ="<%=thisid%>";
var setting = {
		view: {
			selectedMulti: false
		},
		edit: {
			enable: true,
			editNameSelectAll: true,
			showRemoveBtn: false,
			showRenameBtn: false
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			beforeDrag: beforeDrag,
			onRightClick : OnRightClick,
			onClick:zTreeOnClick
		}
	};
	//右键
	function OnRightClick(event,treeId,treeNode) {
		alert(treeNode.name+"的Id为："+treeNode.id);
	}
	//禁止拖拽
	function beforeDrag(treeId, treeNodes) {
		return false;
	}
	//点击事件
	function zTreeOnClick(event,treeId,treeNode){
		
		window.parent.rightFrame.location.href = "bind_list.jsp?f_catalog_id="+treeNode.id+"&f_catalog_programatype=<%=f_catalog_programatype%>";
	}
	
	function selectAll() {
		var zTree = $.fn.zTree.getZTreeObj("lefttree");
		zTree.setting.edit.editNameSelectAll =  $("#selectAll").attr("checked");
	}
	$(document).ready(function(){
		$.ajax({
			url:"../catalog/catalog_list.do?f_catalog_id=0&f_catalog_programatype=<%=f_catalog_programatype%>",
			success:function(data){
				zNodes = JSON.parse(data);
				var root = {id:"0",name:"根目录",open:false};
				zNodes.push(root);
				var treeObj = $.fn.zTree.init($("#lefttree"), setting, zNodes);
				$("#selectAll").bind("click", selectAll);
				treeObj.expandAll(false);//默认关闭所有子分类 
				updateNoParentNode(treeObj);
				//定位到当前修改的分类
				var node = treeObj.getNodeByParam("id",thisid);
				treeObj.cancelSelectedNode();//先取消所有的选中状态
				treeObj.selectNode(node,true);//将指定ID的节点选中
				treeObj.expandNode(node, true, false);//将指定ID节点展开
			
			}
		});
	});
	
	function updateNoParentNode(treeObj){
		var nodesArr = treeObj.transformToArray(treeObj.getNodes());
		for(var i=0;i<nodesArr.length;i++){
			var rootNode = null;
			if(nodesArr[i].pId == null && nodesArr[i].id == '0'){
				rootNode = nodesArr[i];
				break;
			}
		}
		for(var i=0;i<nodesArr.length;i++){
			if(nodesArr[i].pId == null && nodesArr[i].id != '0'){
				treeObj.moveNode(treeObj.moveNode(rootNode, nodesArr[i], "inner"));
			}
		}
	}
	
	
	
</script>
</head>
<body style="background: #FFFFFF;">
	<div id="left" style="width: 100%; overflow: auto; float: left;">
		<ul id="lefttree" class="ztree"></ul>
	</div>
</body>
</html>